package cn.latsen.springboot;

import cn.latsen.springboot.entities.Users;
import cn.latsen.springboot.mappers.UsersMapper;
import cn.latsen.springboot.services.IndexService;
import org.apache.catalina.security.SecurityUtil;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class IndexController {
    @Autowired
    private UsersMapper mapper;
    @Autowired
    private IndexService indexService;
    @RequestMapping("/index")
    public ModelAndView index()
    {
        ModelAndView modelAndView=new ModelAndView();
        modelAndView.setViewName("index");
        Users users=mapper.selectByPrimaryKey(1);
        modelAndView.addObject("userList",users);
        Subject currentUser = SecurityUtils.getSubject();
        String uName="冯科";
        String uPass="123";
        UsernamePasswordToken token=new UsernamePasswordToken(uName,uPass);
        currentUser.login(token);
        return modelAndView;
    }
    @RequiresRoles("user")
    @RequestMapping("/test")
    public ModelAndView test()
    {
        System.out.println("进入");
        ModelAndView modelAndView=new ModelAndView("index");
        return modelAndView;
    }
}